Skip to content

Add warnHandler to allow users to set a custom warn callback #5883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2017

Conversation

lbennett-stacki
Copy link
Contributor

@lbennett-stacki lbennett-stacki commented Jun 14, 2017

Similar to errorHandler, but for warnings. https://vuejs.org/v2/api/#errorHandler

Sorry for not following the "Ideally you should open a suggestion issue first and have it greenlighted before working on it." rule, no loss on my side if you don't want to accept this.

I would like this feature as it will allow Vue to call a user provided callback for warnings which helps for asserting the state of warnings during testing or development, without having to either spyon or monkeypatch the console.error function.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

(sorry!)

Other information:

jsfiddle example: https://jsfiddle.net/vx0ks9yo/3/

@lbennett-stacki
Copy link
Contributor Author

If this feature is wanted, I will, of course, open a PR for the API docs.


warn(msg, vm)

expect(msg).toHaveBeenWarned()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toHaveBeenWarned currently still regards something being "warned" when it calls console.error (warnHandler is not set). Did we want to change this so it also tracks if a custom warnHandler has been called?


warn(msg, vm)

expect(Vue.config.warnHandler).toHaveBeenCalledWith(msg, vm, jasmine.any(String))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see here, I don't explicitly match the trace argument as I cannot spy the generateComponentTrace method without exporting it and wanted to avoid that without approval from a maintainer.

@lbennett-stacki lbennett-stacki changed the title Add warnHandler to allow users to set a custom warn callback WIP: Add warnHandler to allow users to set a custom warn callback Jun 14, 2017
@lbennett-stacki lbennett-stacki changed the title WIP: Add warnHandler to allow users to set a custom warn callback Add warnHandler to allow users to set a custom warn callback Jun 14, 2017
@lbennett-stacki
Copy link
Contributor Author

Added a jsfiddle example in the description. Sorry it's so slow, didn't want to upload my dist file so just pasted it inline. 😬

@yyx990803
Copy link
Member

yyx990803 commented Jun 14, 2017

Thanks - this is great! I can also imagine some creative use cases during development (e.g. warning overlays)

@yyx990803 yyx990803 merged commit 9831b40 into vuejs:dev Jun 14, 2017
@lbennett-stacki
Copy link
Contributor Author

Thanks @yyx990803!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants